package ReSofting.it.GoldDirector.JsonTrans;

import java.io.UnsupportedEncodingException;
import java.util.UUID;

import org.apache.http.entity.StringEntity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONStringer;

import ReSofting.it.GoldDirector.Model.myMenu;
import ReSofting.it.GoldDirector.Model.myOrdine;
import android.util.Log;

public class JsonTransformer_myMenu
{
	/*
	 String Name = pJsObj.getString("");
	 int ID = pJsObj.getInt("");	
	 res = UUID.fromString((String) pJsObj.get("guidmn"));
	 */
	public myMenu jsonTo_myMenu(JSONObject pJsObj)
	{
		if(pJsObj == null) return null;
		
		 try {
			 myMenu res = 
				 new myMenu(
						 UUID.fromString((String) pJsObj.get("guidmn")),
						 pJsObj.getString("FkCategoria"),
						 pJsObj.getString("Nome")
			 );
			 res.Prezzo = (float) pJsObj.getDouble("Prezzo");
			 
			 return res ;
			 
		} catch (JSONException e) {
			Log.v("Errore from Json to Obj in  jsonTo_myMenu ", e.getMessage());
			e.printStackTrace();
			return null;
		}
    	 
	}//fM
	
	public StringEntity myMenu_ToJson(myMenu pObj)
	{
		if(pObj == null) return null;
		
		 try {
        	 
        	 
            JSONStringer oggetto = new JSONStringer()
            .object()
                .key("menu")
                    .object()
                        .key("guidmn").value(UUID.randomUUID())
                        .key("FkCategoria").value(pObj.FkCategoria)
                        .key("Nome").value(pObj.Nome)
                        //.key("Prezzo").value(pObj.Prezzo)
                    .endObject()
                .endObject();
            
            Log.d("Diego", oggetto.toString());
 
            StringEntity dati = new StringEntity(oggetto.toString());
            return dati;
			
		 } 
		 catch (UnsupportedEncodingException ex1) {
			 	Log.v("Errore from Json to Obj in  myMenu_ToJson ", ex1.getMessage());
				ex1.printStackTrace();
				return null;
		}            
		 catch (JSONException ex) {
			Log.v("Errore from Json to Obj in  myMenu_ToJson ", ex.getMessage());
			ex.printStackTrace();
			return null;
		}
 	catch (Exception e) {
		Log.v("Errore from Json to Obj in  myMenu_ToJson ", e.getMessage());
		e.printStackTrace();
		return null;
	}
    	 
	}//fM
	
}
